<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <title>Vue示例</title>

</head>

<body>
<div id="app" v-cloak>
    <ul>
        <template v-for="book in sortedBooks">
            <li>书名：{{book.name}}</li>
            <li>作者：{{book.author}}</li>
        </template>
    </ul>
</div>
<script charset="utf-8" src="../js/vue.min.js" type="text/javascript"></script>
<script type="text/javascript">
    new Vue({
        el: '#app',
        data: {
            books: [{
                name: '《Vue.js实战》',
                author: '梁灏'
            }, {
                name: '《JavaScript 语言精粹》',
                author: 'Douglas Crockford'
            }, {
                name: '《JavaScript 高级程序设计》',
                author: 'Nicholas C.Zakas'
            }]
        },
        computed: {
            filterBooks: function () {
                return this.books.filter(function (book) {
                    return book.name.match(/JavaScript/);
                });
            },
            sortedBooks: function () {
                return this.books.sort(function (a, b) {
                    return a.name.length < b.name.length;
                })
            }
        }
    })
</script>
</body>

</html>
